package net.oschina.app.ui;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import net.oschina.app.R;
import net.oschina.app.fragment.ContentFragment;
import net.oschina.app.fragment.LeftFragment;

public class MainActivity extends AppCompatActivity {
    private ContentFragment mContentFragment;
    private Toolbar toolbar;
    private DrawerLayout drawerlayout;
    private ActionBarDrawerToggle mToggle;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        this.toolbar = (Toolbar) findViewById(R.id.toolbar);
        this.drawerlayout = (DrawerLayout) findViewById(R.id.drawerlayout);
        initView();

    }
    private void initView() {

        mContentFragment = new ContentFragment();

        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        transaction.replace(R.id.fl_left, new LeftFragment(), "left");
        transaction.replace(R.id.fl_content, mContentFragment, "content");
        transaction.commit();

        toolbar.setTitle("开源中国");

        toolbar.setTitleTextColor(Color.WHITE);
        setSupportActionBar(toolbar);
        //1. 产生ActionBarDrawerToggle的对象
        mToggle = new ActionBarDrawerToggle(this, drawerlayout, toolbar, R.string.open, R.string.close);
        //2 同步
        mToggle.syncState();
        //3 给DrawerLayout设置监听
        drawerlayout.addDrawerListener(mToggle);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.search_menu,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.search_content:
                break;
        }
        return super.onOptionsItemSelected(item);
    }


}
